<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'teacher.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<SCRIPT type="text/javascript" src="./js/jquery-1.8.0.min.js"></SCRIPT>
	<script type="text/javascript">
		function deptteacher(id){
			location.href="../teacher/teacher!selectteacher.action?deptid="+id;
		}
		
		function shwodept(id){
			location.href="../teacher/teacher!updateteacher.action?deptid="+deptid+"&id="+id;
		}
		function deleteTeacher(tid){
			$.ajax({
				type:"post",
				url:"./teacher!countClasses.action",
				data:{n:Math.random(),"teacher.id":tid},
				success:function(msg){
					if(msg==0){
						window.location.href="./teacher!deleteteacher.action?teacher.id="+tid;
					}else{
						if(confirm("该教师带有班级，是否确定删除")){
							window.open("./teacher!changeTeaForClasses.action?teacher.id="+tid,null,"width=800px;height=100px");
						}
					}
				}
			});
		}
	</script>
	<style type="text/css">
		table tr td{
			border: 1px solid #CCCCCC;
			width: 200px;
		}
	</style>
  </head>
  
  <body>
  	<table style="border: 1px solid blue;">
  		<tr>
  			<td>
  				部门查询：
  			</td>
  			<td>
  				<s:select theme="simple" list="#request.dept" listKey="id" listValue="name" headerKey="-1" headerValue="=全部="  onchange="deptteacher(this.value);" />
  			</td>
  		</tr>
  		<tr>
			<td>姓名</td>
			<td>部门</td>
			<td>类型</td>
			<td></td>
  		</tr>
  		<s:iterator value="#request.teacher" var="tc">
  			<tr>
  				<td>
  					<s:property value="#tc.name"/>
  				</td>
  				<td id="pro_${tc.id}" onclick="shwodept(this);">
  					<s:property value="#tc.dept.name"/>
  				</td>
  				<td>
  					<s:property value="#tc.isPro==0?'专业老师':'班主任'"/>
  				</td>
  				<td>
  					<a href="./teacher/teacher!updateselectteacher.action?id=${tc.id}">编辑</a>
  					<a onclick="deleteTeacher(${tc.id});">删除教师</a>
  				</td>
  			</tr>
  		</s:iterator>
  	</table>
  </body>
</html>
